package com.office.automate.employee.data.validator;

import java.util.Date;

import com.office.automate.dataaccess.def.user.EmployeeDao;
import com.office.automate.dataaccess.impl.user.EmployeeDaoImplementer;
import com.office.automate.exception.employee.EmployeeExceptionKeys;
import com.office.automate.exception.framework.FrontierVisibleException;
import com.office.automate.exception.general.GeneralException;
import com.office.automate.validation.framework.BaseValidator;

public class EmployeeBaseDataValidator extends BaseValidator {

	EmployeeDao employeeDao = new EmployeeDaoImplementer();

	protected void validateUsername(String aUsername) {
		if (aUsername == null || aUsername.isEmpty()) {
			addFieldValidationException("Username", new FrontierVisibleException(EmployeeExceptionKeys.USERNAME_IS_EMPTY, null));
		}
	}

	protected void validatePassword(String aPassword) {
		if (aPassword == null || aPassword.isEmpty()) {
			addFieldValidationException("Password", new FrontierVisibleException(EmployeeExceptionKeys.PASSWORD_IS_EMPTY, null));
		}
	}

	protected void validateConfirmPassword(String aPassword, String aConfirmPassword) {
		if (aConfirmPassword == null || aConfirmPassword.isEmpty()) {
			addFieldValidationException("ConfirmPassword", new FrontierVisibleException(EmployeeExceptionKeys.CONFIRM_PASSWORD_IS_EMPTY, null));
		} else if (aPassword != null && !aPassword.equals(aConfirmPassword)) {
			addFieldValidationException("ConfirmPassword", new FrontierVisibleException(EmployeeExceptionKeys.PASSWORD_IS_NOT_MATCH_WITH_CONFIRM_PASSWORD, null));
		}
	}

	protected void validateSecurityLevel(int aSecurityLevel) {
		if (aSecurityLevel == -1) {
			addFieldValidationException("SecurityLevel", new FrontierVisibleException(EmployeeExceptionKeys.SECURITY_LEVEL_IS_EMPTY, null));
		}
	}

	protected void validateFirstName(String aFirstName) {
		if (aFirstName == null || aFirstName.isEmpty()) {
			addFieldValidationException("FirstName", new FrontierVisibleException(EmployeeExceptionKeys.FIRSTNAME_IS_EMPTY, null));
		}
	}

	protected void validateMiddleName(String aMiddleName) {
		if (aMiddleName == null || aMiddleName.isEmpty()) {
			addFieldValidationException("MiddleName", new FrontierVisibleException(EmployeeExceptionKeys.MIDDLENAME_IS_EMPTY, null));
		}
	}

	protected void validateLastName(String aLastName) {
		if (aLastName == null || aLastName.isEmpty()) {
			addFieldValidationException("LastName", new FrontierVisibleException(EmployeeExceptionKeys.LASTNAME_IS_EMPTY, null));
		}
	}

	protected void validateNicNumber(String aNicNumber) {
		if (aNicNumber == null || aNicNumber.isEmpty()) {
			addFieldValidationException("NicNumber", new FrontierVisibleException(EmployeeExceptionKeys.NIC_NUMBER_IS_EMPTY, null));
		}
	}

	protected void validateEmail(String aEmail) {
		if (aEmail == null || aEmail.isEmpty()) {
			addFieldValidationException("Email", new FrontierVisibleException(EmployeeExceptionKeys.EMAIL_IS_EMPTY, null));
		}
	}

	protected void validateNationality(String aNationality) {
		if (aNationality == null || aNationality.isEmpty()) {
			addFieldValidationException("Nationality", new FrontierVisibleException(EmployeeExceptionKeys.NATIONALITY_IS_EMPTY, null));
		}
	}

	protected void validateAddressLine1(String aAddressLine1) {
		if (aAddressLine1 == null || aAddressLine1.isEmpty()) {
			addFieldValidationException("AddressLine1", new FrontierVisibleException(EmployeeExceptionKeys.ADDRESS_LINE_1_IS_EMPTY, null));
		}
	}

	protected void validateAddressLine2(String aAddressLine2) {
		if (aAddressLine2 == null || aAddressLine2.isEmpty()) {
			addFieldValidationException("AddressLine2", new FrontierVisibleException(EmployeeExceptionKeys.ADDRESS_LINE_2_IS_EMPTY, null));
		}
	}

	protected void validateCity(String aCity) {
		if (aCity == null || aCity.isEmpty()) {
			addFieldValidationException("City", new FrontierVisibleException(EmployeeExceptionKeys.CITY_IS_EMPTY, null));
		}
	}

	protected void validateZipCode(int aZipCode) {
		if (aZipCode == -1) {
			addFieldValidationException("ZipCode", new FrontierVisibleException(EmployeeExceptionKeys.ZIP_CODE_IS_EMPTY, null));
		}
	}

	protected void validateSalary(double aSalary) {
		if (aSalary == (double)-1) {
			addFieldValidationException("Salary", new FrontierVisibleException(EmployeeExceptionKeys.SALARY_IS_EMPTY, null));
		}
	}

	protected void validateDateOfBirth(Date aDateOfBirth) {
		if (aDateOfBirth.equals(new Date(0))) {
			addFieldValidationException("DateOfBirth", new FrontierVisibleException(EmployeeExceptionKeys.DATE_OF_BIRTH_IS_INVALID, null));
		}
	}

	protected void validateGender(String aGender) {
		if (aGender == null || aGender.isEmpty()) {
			addFieldValidationException("Gender", new FrontierVisibleException(EmployeeExceptionKeys.GENDER_IS_EMPTY, null));
		}
	}

	protected void validateCivilStatus(String aCivilStatus) {
		if (aCivilStatus == null || aCivilStatus.isEmpty()) {
			addFieldValidationException("CivilStatus", new FrontierVisibleException(EmployeeExceptionKeys.CIVIL_STATUS_IS_EMPTY, null));
		}
	}

	protected void validateDesignation(int aDesignation) {
		if (aDesignation == -1) {
			addFieldValidationException("Designation", new FrontierVisibleException(EmployeeExceptionKeys.DESIGNATION_IS_EMPTY, null));
		}
	}

	protected void validateBranch(long aBranch) {
		if (aBranch == -1) {
			addFieldValidationException("Branch", new FrontierVisibleException(EmployeeExceptionKeys.BRANCH_IS_EMPTY, null));
		}
	}

	protected void validateDivision(long aDivision) {
		if (aDivision == -1) {
			addFieldValidationException("Division", new FrontierVisibleException(EmployeeExceptionKeys.DIVISION_IS_EMPTY, null));
		}
	}

	protected void validateManagerOrSupervisor(long aManager) {
		if (aManager == -1) {
			addFieldValidationException("Manager", new FrontierVisibleException(EmployeeExceptionKeys.MANAGER_SUPERVISOR_IS_EMPTY, null));
		}
	}

	protected void validateCompanyJoinedDate(Date aJoinedDate) {
		if (aJoinedDate.equals(new Date(0))) {
			addFieldValidationException("JoinedDate", new FrontierVisibleException(EmployeeExceptionKeys.COMPANY_JOINED_DATE_IS_EMPTY, null));
		}
	}

	protected void validateEmployeeDescription(String aEmployeeDescription) {
		if (aEmployeeDescription == null || aEmployeeDescription.isEmpty()) {
			addFieldValidationException("EmployeeDescription", new FrontierVisibleException(EmployeeExceptionKeys.EMPLOYEE_DESCRIPTION_IS_EMPTY, null));
		}
	}

	protected void validateEmployeeNumber(long anEmployeeNumber) {
		if (anEmployeeNumber == -1) {
			addFieldValidationException("Employee", new FrontierVisibleException(EmployeeExceptionKeys.EMPLOYEE_NUMBER_IS_EMPTY, null));
		} else {
			try {
				if (!employeeDao.isEmployeeExist(anEmployeeNumber)) {
					addFieldValidationException("Employee", new FrontierVisibleException(EmployeeExceptionKeys.EMPLOYEE_NUMBER_IS_INVALID, null));
				}
			} catch (FrontierVisibleException e) {
				addFieldValidationException("GeneralError", new FrontierVisibleException(GeneralException.SYSTEM_ERROR, null));
			}	
		}
	}

	protected void validateQualificationDescription(String aDescription) {
		if (aDescription == null || aDescription.isEmpty()) {
			addFieldValidationException("Description", new FrontierVisibleException(EmployeeExceptionKeys.QUALIFICATION_DESCRIPTION, null));
		}
	}

	protected void validateQualificationType(String aQualificationType) {
		if (aQualificationType == null || aQualificationType.isEmpty()) {
			addFieldValidationException("QualificationType", new FrontierVisibleException(EmployeeExceptionKeys.QUALIFICATION_TYPE, null));
		}
	}

	protected void validateStartAndEndDates(Date aStartDate, Date aEndDate) {
		if (aStartDate.equals(new Date(0))) {
			addFieldValidationException("StartDate", new FrontierVisibleException(EmployeeExceptionKeys.START_DATE_IS_EMPTY, null));
		}

		if (aEndDate.equals(new Date(0))) {
			addFieldValidationException("EndDate", new FrontierVisibleException(EmployeeExceptionKeys.END_DATE_IS_EMPTY, null));
		} else if (!aStartDate.equals(new Date(0)) && aEndDate.before(aStartDate)) {
			addFieldValidationException("EndDate", new FrontierVisibleException(EmployeeExceptionKeys.START_DATE_SHOULD_EARLIER_THAN_END_DATE, null));
		}
	}

	protected void validatePaymentType(String aPaymentType) {
		if (aPaymentType == null || aPaymentType.isEmpty()) {
			addFieldValidationException("PaymentType", new FrontierVisibleException(EmployeeExceptionKeys.PAYMENT_TYPE_IS_EMPTY, null));
		}
	}

	protected void validateBankName(String aBankName) {
		if (aBankName == null || aBankName.isEmpty()) {
			addFieldValidationException("BankName", new FrontierVisibleException(EmployeeExceptionKeys.BANK_NAME_IS_EMPTY, null));
		}
	}

	protected void validateAccountNumber(int anAccountNumber) {
		if (anAccountNumber == -1) {
			addFieldValidationException("AccountNo", new FrontierVisibleException(EmployeeExceptionKeys.ACCOUNT_NUMBER_IS_INVALID, null));
		}
	}

	protected void validateContactNumber(int aContactNumber) {
		if (aContactNumber == -1) {
			addFieldValidationException("ContactNo", new FrontierVisibleException(EmployeeExceptionKeys.CONTACT_NUMBER_IS_INVALID, null));
		}
	}
}
